/***************************************************************************
 *   Copyleft 2006-2007 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>									   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#ifndef __TRIGREGORY_H__
#define __TRIGREGORY_H__

#include "../Curves/BezierCurve.h"
#include "./GregorySurface.h"

class TriGregory: public Object3D {
private:
	DynamicArray2D<Point4D> mMidSurfaces[3];
	DynamicArray2D<Point4D> mOldSurfaces[3];

	cVoid FillGregory();
	cVoid MakeBorderCurves();
	cVoid MakeMidPatch(BezierSurface *patch, DynamicArray2D<Point4D> &out);
	cVoid CorrectPatches();
	cVoid PreventContinuity();
	cVoid DeleteMixDeriv(GregorySurface *g, cInt i, cInt j, cBool u, cBool v);

protected:
	BezierSurface* mBezierSurfaces[3];
	GregorySurface* mGregorySurfaces[3];
	BezierCurve* mBezierCurves[3];

	cBool mMeshVisible;
	cBool mPointsVisible;
	cInt mBezierPrecision;
	cInt mGregoryPrecision;
	cFloat mCurveParam;
	cInt mContinuity;

public:

    /**************************************************************
    * Constructors                                                *
    ***************************************************************/
    TriGregory(BezierSurface *p1, BezierSurface *p2, BezierSurface *p3);
    virtual ~TriGregory(); 
        
    /**************************************************************
    * Operators                                                   *
    ***************************************************************/


    /**************************************************************
    * Other helpful functions                                     *
    ***************************************************************/	
	virtual cVoid Render(Renderer& renderer, Matrix4D& matrix, ProjectionPlane& plane);
	virtual cVoid Render(Renderer& renderer, Matrix4D& matrix, ProjectionPlane& plane, cWinColor color);
	virtual cVoid DisplayInfo(Renderer& renderer);
	virtual cChar* GetName();
	

	cVoid SetMeshVisible(cBool v);
	cBool GetMeshVisible();
	cVoid SetPointsVisible(cBool v);
	cBool GetPointsVisible();
	cVoid SetBezierPrecision(cInt prec);
	cInt GetBezierPrecision();
	cVoid SetGregoryPrecision(cInt prec);
	cInt GetGregoryPrecision();
	cVoid SetCurveParam(cFloat param);
	cFloat GetCurveParam();
	cVoid ToggleContinuity();
};                                                                 

#endif // __TRIGREGORY_H__